import {
	IndexViewActionType,
	IIndexViewAbility,
	IIndexViewControllerParams,
	IIndexViewModel,
	IIndexViewStore,
	IParam,
	IViewEvent,
	IProjectSetting,
} from '@/core';
import { QXEvent } from 'qx-util';
import {
	getIndexViewClassNames,
	useViewAction,
	useViewBasic,
	useViewControllerParams,
	useViewProps,
} from '../use-view';

/**
 * 获取首页视图输入参数
 *
 * @export
 * @return {*}
 */
export function useIndexViewProps() {
	return {
		...useViewProps(),
		appIconPath: {
			type: String,
			default: '',
		},
	};
}

/**
 * 获取首页视图基础
 *
 * @export
 * @param {IIndexViewModel} model 首页视图模型
 * @param {IParam} props 输入参数
 * @return {*}
 */
export function useIndexViewBasic(model: IIndexViewModel, props: IParam) {
	const projectSetting: IProjectSetting = App.getProjectSetting();
	const mainMenuPosition = projectSetting.menuSetting.mainMenuPosition;
	const getClassNames = (props: IParam) => {
		const classNames = getIndexViewClassNames(model, props);
		Object.assign(classNames, {
			[`app-vc-menu--${mainMenuPosition.toLowerCase()}`]: true,
		});
		return classNames;
	};
	return {
		...useViewBasic(model, props),
		getClassNames,
	};
}

/**
 * 首页视图行为
 *
 * @export
 */
export function useIndexViewAction(controller: any) {
	return {
		...useViewAction(controller),
	};
}

/**
 * 获取首页视图控制器输入参数
 *
 * @export
 * @param {IIndexViewModel} model
 * @param {IParam} props
 * @param {QXEvent<IViewEvent<IndexViewActionType, IIndexViewAbility>>} evt
 * @return {*}  {IIndexViewControllerParams<IndexViewActionType, IIndexViewAbility>}
 */
export function useIndexViewControllerParams(
	model: IIndexViewModel,
	props: IParam,
	evt: QXEvent<IViewEvent<IndexViewActionType, IIndexViewAbility>>
): IIndexViewControllerParams<IndexViewActionType, IIndexViewAbility> {
	return {
		...useViewControllerParams<IIndexViewStore, IIndexViewModel>(
			model,
			props,
			evt
		),
	};
}
